package qjc.o_动态规划;

public class o10_乘积最大数组 {
    public int maxProduct(int[] nums) {
        int maxProd = nums[0];
        int maxCur = nums[0];
        int minCur = nums[0];
        for (int i = 1; i < nums.length; i++) {
            int num = nums[i];
            int tempMax = maxCur;
            int tempMin = minCur;
            maxCur = Math.max(num, Math.max(tempMax * num, tempMin * num));
            minCur = Math.min(num, Math.min(tempMax * num, tempMin * num));
            maxProd = Math.max(maxProd, maxCur);
        }
        return maxProd;
    }
}
